/**
 * 
 */
var db;

function initDb() {
	console.log('create database');
	db = window.openDatabase("eb", "1.0", "Electric bill DB", 1000000);
	db.transaction(populateDB, errorCB, successCB);
}

function populateDB(tx) {
	tx.executeSql('DROP TABLE IF EXISTS ELECTRIC_BILL');
	tx
			.executeSql('CREATE TABLE IF NOT EXISTS ELECTRIC_BILL (bill_date, bill_nbr, bill_type, bill_comment, bill_win_price,datestamp, is_win )');
}

function errorCB(err) {
	alert("Error processing SQL: " + err.code);
}

function successCB() {
	// alert("success!");
	// db.transaction(queryDB, errorCB);
}

function insertEb(eb, success, fail) {
	db
			.transaction(function(tx) {
				console.log("eb insert: ");
				console.log(eb);
				tx
						.executeSql(
								'INSERT INTO ELECTRIC_BILL (bill_date, bill_nbr, bill_type, bill_comment, bill_win_price ,datestamp,is_win) VALUES (?, ?,?,?,?,?,?)',
								[ eb.date, eb.nbr, eb.type, eb.comment,
										eb.price, eb.datestamp,eb.win ], fail, success);
			});
}

function queryEb(date,success, fail) {
	db
	.transaction(function(tx) {
		console.log(date);
		//console.log("eb insert: ");
		//console.log(eb);
		tx
				.executeSql(
						'select * from ELECTRIC_BILL;',
						[], success, fail);
	});
	
}
